<?php
/*
    Author : Gisca
    Akses pada data Role
*/

    class Role extends CI_Model
    {
        function Role_model() {
                parent::Model();
        }

        //fungsi-fungsi yang berhubungan dengan pengelolaan role pengguna
        public function getRolePengguna($user_id)
        {
             $sql = "select * from role where userID = '$user_id'";
             $query = $this->db->query($sql);
                if ($query->num_rows() > 0){
                        $result = array();
                        foreach($query->result_array() as $row){
                                $result[] = $row;
                        }
                        return $result;
                 }
        }

        public function updateRolePengguna($rolename, $userid)
        {
            $sql = "replace into role values ('$rolename','$userid')";
            $this->db->query($sql);
        }

        public function deleteRolePengguna($rolename, $user_id)
        {
            $sql = "delete from role where roleName='$rolename' AND userID='$user_id'";
            $this->db->query($sql);
        }

        public function deleteRole($user_id)
        {
            $sql = "delete from role where userID='$user_id'";
            $this->db->query($sql);
        }

    }
?>
